import 'dart:ui';
import 'package:flutter/material.dart';
import 'package:fluttertoast/fluttertoast.dart';
import '../utils/ScreenAdapter.dart';

class Utils {
  static final GlobalKey<NavigatorState> navigatorKey = GlobalKey();

  static Map systemInfo = {"topBloodHeight": MediaQueryData.fromWindow(window).padding.top, "bottomBloodHeight": MediaQueryData.fromWindow(window).padding.bottom};

  // 全局弹窗组件
  static Future toast(String text) => Fluttertoast.showToast(
      msg: text, toastLength: Toast.LENGTH_SHORT, gravity: ToastGravity.CENTER, timeInSecForIosWeb: 1, backgroundColor: Colors.black45, textColor: Colors.white, fontSize: ScreenAdapter.size(20));

  /// 获取当前页面的state
  static NavigatorState getCurrentState() => navigatorKey.currentState;

  /// 获取当前页面的context
  static BuildContext getCurrentContext() => navigatorKey.currentContext;

  /// 跳转页面使用 G.pushNamed
  static void pushNamed(String routeName, {Object arguments}) {
    getCurrentState().pushNamed(routeName, arguments: arguments);
    // // 如果跳转到toolbar页面  不能返回
    // if (toobarRouteNameList.indexOf(routeName) > -1) {
    //   getCurrentState().pushReplacementNamed(
    //     routeName,
    //     arguments: arguments,
    //   );
    // } else {
    //   getCurrentState().pushNamed(routeName, arguments: arguments);
    // }
  }

  static void pageBack() => getCurrentState().pop();
}
